package com.cheyunkeji.er.utils;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
//import com.bumptech.glide.request.target.GlideDrawableImageViewTarget;
import com.cheyun.netsalev3.R;
import com.cheyun.netsalev3.MyApplication;

import androidx.fragment.app.Fragment;


/**
 * Created by Michael on 2017/2/16 18:24.
 */

public class ImageLoadUtil {

    public static void loadImg(Context context, String url, ImageView imageView) {
        Glide.with(context).load(url).centerCrop().error(R.drawable.er_default_img_select_bkg).
                fallback(R.drawable.er_default_img_select_bkg).
                into(imageView);
    }

    public static void loadImgWithoutAnimate(Context context, String url, ImageView imageView) {
        Glide.with(context).load(url).centerCrop().dontAnimate().into(imageView);
    }

    public static void loadImgInFrag(Fragment fragment, String url, ImageView imageView) {
        Glide.with(fragment).load(url).centerCrop().error(R.drawable.er_default_img_select_bkg).
                fallback(R.drawable.er_default_img_select_bkg).into(imageView);
    }

    public static void loadLocalImg(Context context, int imgResId, ImageView imageView) {
        Glide.with(context).load(imgResId).centerCrop().error(R.drawable.er_default_img_select_bkg).
                fallback(R.drawable.er_default_img_select_bkg).into(imageView);
    }

//    public static void loadImgWithSuccessListener(Context context, String url, GlideDrawableImageViewTarget listener) {
//        Glide.with(context).load(url).centerCrop().error(R.drawable.er_default_img_select_bkg).
//                fallback(R.drawable.er_default_img_select_bkg).into(listener);
//    }

    public static void clearCache() {
        Glide.get(MyApplication.getInstance()).clearMemory();
        Glide.get(MyApplication.getInstance()).clearDiskCache();
    }
}
